"""
url：http://www.bjhospital.net/
用例1：
搜索骨科—>点击搜索—>点击出来的第一个链接—>断言文本内容
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
option = webdriver.EdgeOptions() # todo：chrome浏览器配置项
option.add_experimental_option("detach", True)# todo：浏览器不会自动关闭
driver = webdriver.Edge(options=option)
driver.get("http://www.bjhospital.net/")
driver.maximize_window() # 全屏
driver.implicitly_wait(15)
driver.find_element(By.NAME,"q").send_keys("骨科")
# 通过xpath点击定位
driver.find_element(By.CLASS_NAME,'btn').click()
driver.find_element(By.XPATH,'/html/body/div[4]/ul/li[1]/div[1]/h5/a').click()
win = driver.window_handles
driver.window_handles
driver.switch_to.window(win[-1])
text_result = driver.find_element(By.XPATH,'/html/body/div[3]/div/div/article/h1').text
assert text_result == "毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"
# 获取浏览器title
print(driver.title)

# 退出浏览器
driver.quit()